import { createStore } from 'vuex'

export default createStore({
  state: {
    token: '',
    username: '',
    userInfos: JSON.parse(localStorage.getItem('userInfos') || '{}'),
    versionsVal: '0',
  },
  mutations: {
    changeUser(state, userData) {
      localStorage.token = userData.role // 存入lacalstorage
      localStorage.username = userData.username
      state.token = userData.role
      state.username = userData.username
      // console.log(state.token, state.username)
    },
    rememberPwd(state, userInfos) {
      localStorage.setItem('userInfos', JSON.stringify(userInfos))
      state.userInfos = userInfos
      console.log(state.userInfos)
    },
    // 选择版本
    VuexVersions(state, versionsVal) {
      state.versionsVal = versionsVal
      console.log(state.versionsVal)
    },
  },
  actions: {},
  modules: {},
})
